<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>公司信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{/statics/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/statics/style/admin.css}" media="all">
    <link rel="stylesheet" th:href="@{/statics/wang/wangeditor.css}">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">公司信息</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="layuiadmin-form-company">
                <div class="layui-form-item">
                    <label class="layui-form-label">公司名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入公司名称"
                               class="layui-input" th:value="${company.name}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">公司地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="address" lay-verify="required" placeholder="请输入公司地址" autocomplete="off"
                               class="layui-input" th:value="${company.address}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮政编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="postcode" lay-verify="required" placeholder="请输入邮政编码"
                               autocomplete="off" class="layui-input" th:value="${company.postcode}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-block">
                        <input type="text" name="linkman" lay-verify="required" placeholder="请输入联系人" autocomplete="off"
                               class="layui-input" th:value="${company.linkman}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" lay-verify="required" placeholder="请输入手机号码" autocomplete="off"
                               class="layui-input" th:value="${company.mobile}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电话号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="telephone" lay-verify="required" placeholder="请输入电话号码"
                               autocomplete="off" class="layui-input" th:value="${company.telephone}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">传真号码</label>
                    <div class="layui-input-block">
                        <input type="text" name="fax" lay-verify="required" placeholder="请输入传真号码" autocomplete="off"
                               class="layui-input" th:value="${company.fax}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电子邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" lay-verify="required" placeholder="请输入电子邮箱" autocomplete="off"
                               class="layui-input" th:value="${company.email}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">公司简介</label>
                    <div class="layui-input-block">
                        <textarea id="introduction" name="introduction" placeholder="请输入公司简介" class="layui-textarea" style="height: 400px;">[[${company.introduction}]]</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <input type="hidden" name="lang" th:value="${currentlanguage.code}" autocomplete="off"
                               class="layui-input">
                        <button class="layui-btn" lay-submit="" id="LAY-company-form-submit"
                                lay-filter="LAY-company-form-submit">立即提交
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script th:src="@{/statics/layui/layui.js}"></script>
<script>
    layui.config({
        base: '/statics/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'wangeditor'], function () {
        var $ = layui.$
            , admin = layui.admin
            , element = layui.element
            , layer = layui.layer
            , wang = layui.wangeditor('#introduction')
            , form = layui.form;

        form.render(null, 'layuiadmin-form-company');

        wang.config.customUpload = false;
        wang.config.uploadImgUrl = '/cms/wangEditor/local/saveImg';
        wang.config.uploadImgFileName = 'file';
        wang.config.uploadImgFns.onload = function (resultText, xhr) {
            var obj = eval('(' + resultText + ')');
            wang.command(null, 'insertHtml', '<img src="' + obj.data + '" style="max-width:100%;"/>');
        };
        wang.create();

        /* 自定义验证规则 */
        form.verify({
            name: function (value) {
                if (value.length < 2) {
                    return '公司名称至少得5个字符啊';
                }
            }
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        /* 监听提交 */
        form.on('submit(LAY-company-form-submit)', function (data) {
            data.introduction = wang.$txt.html();
            $.ajax({
                url: '/api/company/update',
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                async: true,
                success: function (result) {
                    if (result.code == 0) {
                        layer.msg('保存成功!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('保存失败！' + result.msg, {icon: 2, time: 1000});
                    }
                },
                error: function (err) {
                    layer.msg('保存失败！', {icon: 2, time: 1000});
                }
            });
            return false;
        });
    });
</script>

</body>
</html>
